<!doctype html>


<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>CachingMatcher (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>

  <script type="text/javascript" src="//www.google.com/jsapi"></script>
  <script type="text/javascript">
     google.load("visualization", "1", {packages:["orgchart"]});
     var _loadingVisualizations = true;
  </script>

  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>





<div class="colmask rightmenu">
<div class="colleft">
    <div class="col1">
      <!-- Column 1 start -->

<div id="title">
        <span class="fn">ui.ac.CachingMatcher</span>
        <span>Extends</span>
        <span class="fn-name">
          
        </span>
</div>

<div class="g-section g-tpl-75-25">
  <div class="g-unit g-first" id="description">
    A matcher which wraps another (typically slow) matcher and
keeps a client-side cache of the results. For instance, you can use this to
wrap a RemoteArrayMatcher to hide the latency of the underlying matcher
having to make ajax request.

Objects in the cache are deduped on their stringified forms.

Note - when the user types a character, they will instantly get a set of
local results, and then some time later, the results from the server will
show up.


  </div>


        <div class="g-unit" id="useful-links">
          <div class="title">Useful links</div>
          <ol>
            <li><a href="local_closure_goog_ui_ac_cachingmatcher.js.source.html"><span class='source-code-link'>Source Code</span></a></li>
            <li><a href="http://code.google.com/p/closure-library/source/browse/local/closure/goog/ui/ac/cachingmatcher.js">Git</a></li>
          </ol>
        </div>
</div>






<h2 class="g-first">Inheritance</h2>
<div class='gviz-org-chart-container goog-inline-block'>
<table class='gviz-org-chart' style='display:none'>
  <tr><td>goog.ui.ac.CachingMatcher</td><td></td></tr>
</table>
</div>
<div class='gviz-org-chart-container goog-inline-block'>
<table class='gviz-org-chart' style='display:none'>
</table>
</div>




  <h2>Constructor</h2>
      <div class="fn-constructor">
    goog.ui.ac.CachingMatcher(<span><span class="arg">baseMatcher</span></span>)
  </div>

   <h3>Parameters</h3>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">baseMatcher</span>
        : <span>!</span><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span>
        <div class="entryOverview">The underlying matcher to use. Must implement
    requestMatchingRows.</div>
     </td>
   </tr>
  </table>


<h2>Instance Methods</h2>


  <div class="legend">
        <span class="key publickey"></span><span>Public</span>
        <span class="key protectedkey"></span><span>Protected</span>
        <span class="key privatekey"></span><span>Private</span>
  </div>







<div>
       <div class="desc">
         Defined in
         <span class="fn-name">
            <a href="class_goog_ui_ac_CachingMatcher.html">
              goog.ui.ac.CachingMatcher
            </a>
         </span>
       </div>






<div class="section">
  <table class="horiz-rule">


     <tr class="even entry private">
       <td class="access"></td>






  <td>
    <a name="goog.ui.ac.CachingMatcher.prototype.addRows_"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryName">addRows_<span class="args">(<span class="arg">rows</span>)</span>
        </span>
      </div>


     <div class="entryOverview">
       Adds the specified rows to the cache.

     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">rows</span>
        : <span>!</span><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></span>.&lt;<span>!</span><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span>&gt;
        <div class="entryOverview">.</div>
     </td>
   </tr>
  </table>
      </div>
   
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="local_closure_goog_ui_ac_cachingmatcher.js.source.html#line193">code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry private">
       <td class="access"></td>






  <td>
    <a name="goog.ui.ac.CachingMatcher.prototype.clearCacheIfTooLarge_"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryName">clearCacheIfTooLarge_<span class="args">()</span>
        </span>
      </div>


     <div class="entryOverview">
       Checks if the cache is larger than the maximum cache size. If so clears it.

     </div>

   
  </td>


  <td class="view-code">
     <a href="local_closure_goog_ui_ac_cachingmatcher.js.source.html#line208">code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry private">
       <td class="access"></td>






  <td>
    <a name="goog.ui.ac.CachingMatcher.prototype.getMatchesForRows_"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryName">getMatchesForRows_<span class="args">()</span>
        </span>
      </div>


     <div class="entryOverview">
       Local matching function.

     </div>

   
  </td>


  <td class="view-code">
     <a href="local_closure_goog_ui_ac_cachingmatcher.js.source.html#line74">code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry private">
       <td class="access"></td>






  <td>
    <a name="goog.ui.ac.CachingMatcher.prototype.onBaseMatch_"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryName">onBaseMatch_<span class="args">(<span class="arg">token</span>,&nbsp;<span class="arg">matches</span>)</span>
        </span>
      </div>


     <div class="entryOverview">
       Handles a match response from the base matcher.

     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">token</span>
        : <span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span>
        <div class="entryOverview">The token against which the base match was called.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">matches</span>
        : <span>!</span><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></span>.&lt;<span>!</span><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span>&gt;
        <div class="entryOverview">The matches returned by the base matcher.</div>
     </td>
   </tr>
  </table>
      </div>
   
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="local_closure_goog_ui_ac_cachingmatcher.js.source.html#line234">code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry public">
       <td class="access"></td>






  <td>
    <a name="goog.ui.ac.CachingMatcher.prototype.requestMatchingRows"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryName">requestMatchingRows<span class="args">(<span class="arg">token</span>,&nbsp;<span class="arg">maxMatches</span>,&nbsp;<span class="arg">matchHandler</span>)</span>
        </span>
      </div>


     <div class="entryOverview">
       Function used to pass matches to the autocomplete.

     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">token</span>
        : <span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span>
        <div class="entryOverview">Token to match.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">maxMatches</span>
        : <span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Number">number</a></span>
        <div class="entryOverview">Max number of matches to return.</div>
     </td>
   </tr>
     
   <tr class="even">
     <td>
        <span class="entryName">matchHandler</span>
        : <span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function">Function</a></span>
        <div class="entryOverview">callback to execute after matching.</div>
     </td>
   </tr>
  </table>
      </div>
   
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="local_closure_goog_ui_ac_cachingmatcher.js.source.html#line175">code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry public">
       <td class="access"></td>






  <td>
    <a name="goog.ui.ac.CachingMatcher.prototype.setBaseMatcherMaxMatches"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryName">setBaseMatcherMaxMatches<span class="args">(<span class="arg">maxMatches</span>)</span>
        </span>
      </div>


     <div class="entryOverview">
       Sets the maxMatches to use for the base matcher. If the base matcher makes
AJAX requests, it may help to make this a large number so that the local
cache gets populated quickly.

Default value: 100.


     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">maxMatches</span>
        : <span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Number">number</a></span>
        <div class="entryOverview">The value to set.</div>
     </td>
   </tr>
  </table>
      </div>
   
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="local_closure_goog_ui_ac_cachingmatcher.js.source.html#line132">code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry public">
       <td class="access"></td>






  <td>
    <a name="goog.ui.ac.CachingMatcher.prototype.setLocalMatcher"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryName">setLocalMatcher<span class="args">(<span class="arg">localMatcher</span>)</span>
        </span>
      </div>


     <div class="entryOverview">
       Sets the local matcher to use.

The local matcher should be a function with the same signature as
<code> goog.ui.ac.ArrayMatcher.getMatchesForRows</code>, i.e. its arguments are
searchToken, maxMatches, rowsToSearch; and it returns a list of matching
rows.

Default value: <code> goog.ui.ac.ArrayMatcher.getMatchesForRows</code>.


     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">localMatcher</span>
        : <span class="type">function(string, number, !Array</span>.&lt;<span>!</span><span class="type">Object>): !Array</span>.&lt;<span>!</span><span class="type">Objec</span>&gt;&gt;
        <div class="entryOverview"><span class='nodesc'>No description.</span></div>
     </td>
   </tr>
  </table>
      </div>
   
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="local_closure_goog_ui_ac_cachingmatcher.js.source.html#line164">code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry public">
       <td class="access"></td>






  <td>
    <a name="goog.ui.ac.CachingMatcher.prototype.setMaxCacheSize"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryName">setMaxCacheSize<span class="args">(<span class="arg">maxCacheSize</span>)</span>
        </span>
      </div>


     <div class="entryOverview">
       Sets the maximum size of the local cache. If the local cache grows larger
than this size, it will be emptied.

Default value: 1000.


     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">maxCacheSize</span>
        : <span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Number">number</a></span>
        <div class="entryOverview">.</div>
     </td>
   </tr>
  </table>
      </div>
   
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="local_closure_goog_ui_ac_cachingmatcher.js.source.html#line146">code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry public">
       <td class="access"></td>






  <td>
    <a name="goog.ui.ac.CachingMatcher.prototype.setThrottleTime"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryName">setThrottleTime<span class="args">(<span class="arg">throttleTime</span>)</span>
        </span>
      </div>


     <div class="entryOverview">
       Sets the number of milliseconds with which to throttle the match requests
on the underlying matcher.

Default value: 150.


     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">throttleTime</span>
        : <span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Number">number</a></span>
        <div class="entryOverview">.</div>
     </td>
   </tr>
  </table>
      </div>
   
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="local_closure_goog_ui_ac_cachingmatcher.js.source.html#line117">code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry private">
       <td class="access"></td>






  <td>
    <a name="goog.ui.ac.CachingMatcher.prototype.triggerBaseMatch_"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryName">triggerBaseMatch_<span class="args">()</span>
        </span>
      </div>


     <div class="entryOverview">
       Triggers a match request against the base matcher. This function is
unthrottled, so don't call it directly; instead use
this.throttledTriggerBaseMatch_.

     </div>

   
  </td>


  <td class="view-code">
     <a href="local_closure_goog_ui_ac_cachingmatcher.js.source.html#line222">code &raquo;</a>
  </td>
     </tr>


  </table>
</div>
</div>




<h2>Instance Properties</h2>







<div>
       <div class="desc">
         Defined in
         <span class="fn-name">
            <a href="class_goog_ui_ac_CachingMatcher.html">
              goog.ui.ac.CachingMatcher
            </a>
         </span>
       </div>






<div class="section">
  <table class="horiz-rule">


     <tr class="even entry private">
       <td class="access"></td>





  <a name="goog.ui.ac.CachingMatcher.prototype.baseMatcherMaxMatches_"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryName">baseMatcherMaxMatches_</span>
        : 
     </div>


     <div class="entryOverview">
       <span class='nodesc'>No description.</span>
     </div>

  </td>


  <td class="view-code">
     <a href="local_closure_goog_ui_ac_cachingmatcher.js.source.html#line77">Code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry private">
       <td class="access"></td>





  <a name="goog.ui.ac.CachingMatcher.prototype.baseMatcher_"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryName">baseMatcher_</span>
        : 
     </div>


     <div class="entryOverview">
       <span class='nodesc'>No description.</span>
     </div>

  </td>


  <td class="view-code">
     <a href="local_closure_goog_ui_ac_cachingmatcher.js.source.html#line68">Code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry private">
       <td class="access"></td>





  <a name="goog.ui.ac.CachingMatcher.prototype.maxCacheSize_"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryName">maxCacheSize_</span>
        : 
     </div>


     <div class="entryOverview">
       Maximum number of rows in the cache. If the cache grows larger than this,
the entire cache will be emptied.

     </div>

  </td>


  <td class="view-code">
     <a href="local_closure_goog_ui_ac_cachingmatcher.js.source.html#line65">Code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry private">
       <td class="access"></td>





  <a name="goog.ui.ac.CachingMatcher.prototype.mostRecentMatchHandler_"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryName">mostRecentMatchHandler_</span>
        : 
     </div>


     <div class="entryOverview">
       <span class='nodesc'>No description.</span>
     </div>

  </td>


  <td class="view-code">
     <a href="local_closure_goog_ui_ac_cachingmatcher.js.source.html#line87">Code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry private">
       <td class="access"></td>





  <a name="goog.ui.ac.CachingMatcher.prototype.mostRecentMatches_"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryName">mostRecentMatches_</span>
        : 
     </div>


     <div class="entryOverview">
       The set of rows which we last displayed.

NOTE(reinerp): The need for this is subtle. When a server result comes
back, we don't want to suddenly change the list of results without the user
doing anything. So we make sure to add the new server results to the end of
the currently displayed list.

We need to keep track of the last rows we displayed, because the "similar
matcher" we use locally might otherwise reorder results.


     </div>

  </td>


  <td class="view-code">
     <a href="local_closure_goog_ui_ac_cachingmatcher.js.source.html#line105">Code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry private">
       <td class="access"></td>





  <a name="goog.ui.ac.CachingMatcher.prototype.mostRecentMaxMatches_"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryName">mostRecentMaxMatches_</span>
        : 
     </div>


     <div class="entryOverview">
       <span class='nodesc'>No description.</span>
     </div>

  </td>


  <td class="view-code">
     <a href="local_closure_goog_ui_ac_cachingmatcher.js.source.html#line90">Code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry private">
       <td class="access"></td>





  <a name="goog.ui.ac.CachingMatcher.prototype.mostRecentToken_"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryName">mostRecentToken_</span>
        : 
     </div>


     <div class="entryOverview">
       <span class='nodesc'>No description.</span>
     </div>

  </td>


  <td class="view-code">
     <a href="local_closure_goog_ui_ac_cachingmatcher.js.source.html#line84">Code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry private">
       <td class="access"></td>





  <a name="goog.ui.ac.CachingMatcher.prototype.rowStrings_"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryName">rowStrings_</span>
        : 
     </div>


     <div class="entryOverview">
       Set of stringified rows, for fast deduping. Each element of this.rows_
is stored in rowStrings_ as (' ' + row) to ensure we avoid builtin
properties like 'toString'.

     </div>

  </td>


  <td class="view-code">
     <a href="local_closure_goog_ui_ac_cachingmatcher.js.source.html#line58">Code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry private">
       <td class="access"></td>





  <a name="goog.ui.ac.CachingMatcher.prototype.rows_"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryName">rows_</span>
        : 
     </div>


     <div class="entryOverview">
       <span class='nodesc'>No description.</span>
     </div>

  </td>


  <td class="view-code">
     <a href="local_closure_goog_ui_ac_cachingmatcher.js.source.html#line50">Code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry private">
       <td class="access"></td>





  <a name="goog.ui.ac.CachingMatcher.prototype.throttledTriggerBaseMatch_"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryName">throttledTriggerBaseMatch_</span>
        : <span class="type"><a href="class_goog_async_Throttle.html">goog.async.Throttle</a></span>
     </div>


     <div class="entryOverview">
       <span class='nodesc'>No description.</span>
     </div>

  </td>


  <td class="view-code">
     <a href="local_closure_goog_ui_ac_cachingmatcher.js.source.html#line80">Code &raquo;</a>
  </td>
     </tr>


  </table>
</div>
</div>










<div class="section">
  <table class="horiz-rule">


  </table>
</div>









<div class="section">
  <table class="horiz-rule">


  </table>
</div>









<div class="section">
  <table class="horiz-rule">


  </table>
</div>
      <!-- Column 1 end -->
    </div>

        <div class="col2">
          <!-- Column 2 start -->
          <div class="col2-c">
            <h2 id="ref-head">Package ui.ac</h2>
            <div id="localView"></div>
          </div>

          <div class="col2-c">
            <h2 id="ref-head">Package Reference</h2>
            <div id="sideTypeIndex" rootPath="" current="ui.ac.CachingMatcher"></div>
          </div>
          <!-- Column 2 end -->
        </div>
</div>
</div>

</body>
</html>
